import Vue from 'vue'
import Router from 'vue-router'
// import cesiumViewer from '@/components/cesiumViewer'
// import helloCesium from '@/components/demo/helloCesium'
import hello from '@/components/function/hello'
import Login from '../views/Login'
import Home from '../views/Home'
// import map from '@/components/CesiumContainer'

Vue.use(Router)

//防止重复点击路由时，报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  { path: '/', redirect: '/login' },
  {path: '/login', component: Login },
  {
    path: '/home',
    component: Home,
    redirect: '/components/function/hello',
    children: []
  },
];
$.ajaxSettings.async = false;
$.getJSON('static/MenuConfig.json', (menus) => {
  for(let key in menus){
    menus[key].forEach((item) => {
      routes[2].children.push({
        path: "/components/" + key + "/" + item.name,
        component: resolve => require(["../components/" + key + "/" + item.name + ".vue"], resolve),
      })
    })
  }
})
$.ajaxSettings.async = true;

export default new Router({
  routes
})
